Skip to content

feat: Use live solved counts for today's history entry in fetch-user-info.js (#265)#339

Open
yashvi-3106 wants to merge 1 commit into
codepvg:mainfrom
yashvi-3106:feat-live-solved-counts
Open

feat: Use live solved counts for today's history entry in fetch-user-info.js (#265)#339
yashvi-3106 wants to merge 1 commit into
codepvg:mainfrom
yashvi-3106:feat-live-solved-counts

Conversation

@yashvi-3106

Copy link
Copy Markdown
Contributor

Description

Previously, the user profile page loaded stale solved count metrics for the current day because historical user data is only updated during the scheduled sync interval (every 15 minutes).

This PR updates the /api/user/:username endpoint to extract live solved counts (easySolved, mediumSolved, hardSolved) from the LeetCode wrapper API and dynamically overwrite (or insert) today's history entry with these live values.

Linked Issue

Fixes #265

Changes Made

  • Modified fetchUserInfo() in scripts/fetch-user-info.js to extract easySolved, mediumSolved, and hardSolved counts from the wrapper API response.
  • Integrated the live solved counts into today's history entry (using UTC YYYY-MM-DD date matching).
  • Appends a temporary history entry for today using live counts if the entry does not exist yet (e.g. at the start of a day or for new users).

Type of Change

  • New feature
  • Bug fix
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally by running npx prettier --write . before submitting
  • I am submitting my PR from a dedicated feature/* branch, not the main branch
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write . before requesting a review.
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@@ -85,6 +91,25 @@ async function fetchUserInfo(username) {
history = Array.isArray(history) ? history : [];
history.sort((a, b) => new Date(a.date) - new Date(b.date));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this sorting line below the logic where we insert today's count? While today's entry will technically always be the most recent date, it's generally safer and better practice to sort the array after all insertions or modifications have been made. That way the data is guaranteed to be in the correct order regardless of how it's constructed in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use live solved counts for today's history entry in fetch-user-info.js

2 participants